Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Expand v.IMP Queriesv.IMP Queries
Expand XMLXML
Collapse Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

Use Joins instead of Subqueries

 
      
Capitals
Country Capital
India New Delhi
USA Washington
France Paris
Continents
Country Continent
India Asia
USA N.America
Italy Europe
---- Low Performance using Subqueries
SELECT * FROM Capitals cp WHERE EXISTS (SELECT * FROM Continents cn WHERE cp.Country = cn.Country)
---- High Performance using Joins
SELECT Capitals.* FROM Capitals INNER JOIN Continents ON Capitals.Country=Continents.Country
---- both Queries will give the same output but Performance is different, if the data is tooooo big
Output
Country Capital
India New Delhi
USA Washington